package com.rsa.boot.controller;

import com.rsa.boot.utils.RsaUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author tanghailan
 * @date 2020-10-20 15:51
 */
@RestController
@Slf4j
public class RsaController {

    public static final String privateKey= "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMxZ+cEwtjVJuaAd\n" +
            "usO8URn9EhzN0e8fxV+StGoQH/wVVf4g+K43LQuvlImNtFpTLYIvDA7JNtSxgQ6o\n" +
            "hvePtH8zGkt+Rn1qnrqGIS1fDC7Slvbf9PXqW2jlwtXzuDSvXCLx0dukSa69bHwh\n" +
            "of6s7LCezmDOOPNfy9FkZkE4bjV5AgMBAAECgYAYvGd0EC5uIt96Vz7tRJVYnP6d\n" +
            "R/i6hlEA8aQvFoaYoAiJu3n+tKUaPgWv5NxI9rqSgJloDMk7U8U4fgPgYZ/KcnJE\n" +
            "n8L5hehveywT1S59KZ6yRy5JpCHBsLWvNVZfUoGBZAEZYqH2yF8U9gSveGezRwS6\n" +
            "+ouHmgvt6DwU/jWeAQJBAPH1VEPZJdVLk1c+QFL22UBkicG5G8Xv5DYJbtsU9QyO\n" +
            "Sa0tT6L+tPa7FUiAY6tJVSuWHdZLUjLXa2Bn2BsIq0ECQQDYNfAH7+X+6hnNvCMP\n" +
            "K8BAyJ2HB4P3lXFwNEpgADKq0AviPCPYZSptyvL2YSmCS01K4bZ8tDdPf740ds25\n" +
            "XxQ5AkEA6bmtc3jwpfDCXJVCt6HCTQSRWbQBUxwfW9+S2UiOSlmsbAAIHJBkqK4h\n" +
            "qg5zuQM2pcr1+Yp61afoDpFhXQPrwQJBAKP2o4UhZOYgWlkvJ9dFcpKukOfpxyZm\n" +
            "6pQQ06ZiAAqRo7F5siVU8ww4MHCv1m689GypJ18CvD9JvNDEl9bQR+ECQFxG+0tC\n" +
            "gTrgJNY/y6p+Bnh5MStjHEwHNoN+d+gzjcl44LMhR16P/nJ8KGHdpe7E9v6WJAjl\n" +
            "ETKS7Al3+E6nINg=";

    /**
     * 测试RSA加解密
     * @param pwd 加密后的文本
     * @return
     * @throws Exception
     */
    @PostMapping("/testRsa")
    public String testRsa(@RequestParam String pwd) throws Exception {
        long start = System.currentTimeMillis();
        System.out.println();
        log.info("加密之后的明文是："+pwd);
        log.info("privateKey是："+privateKey);
        String password = RsaUtils.decryptByPrivateKey(privateKey,pwd);
        log.info("解密后的密码为："+password);
        long end = System.currentTimeMillis();
        System.out.println((end-start));
        return password;
    }
}
